<template>

  <div style="text-align: center;" id="user">

    <el-card
        :style="`width: 500px;height: 600px; margin: auto;background-image: url('${require('@/assets/etty.jpg')}');`">
      <!--    <div @click="$router.push('/index')">返回首页</div>-->
      <div slot="header" style="font-size: 30px">
        <!--        首页图标-->
        <div style="text-align: right;float: right">
          <i class="el-icon-s-home" @click="$router.push('/index')" style="font-size: 1em;"></i>
        </div>
        个人信息
      </div>


<!--      <el-form :model="user" :rules="rules" ref="loginForm" class="demo-ruleForm">-->
<!--        <el-form-item label="账号" prop="account" style="font-size: 18px">-->
<!--          <el-input style="width: 400px;background-color: rgba(248,248,248,0.5)" v-model="user.account"></el-input>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="密码" prop="password">-->
<!--          <el-input style="width: 400px" v-model="user.password"></el-input>-->
<!--        </el-form-item>-->


<!--        <el-form-item>-->
<!--          <el-button type="primary" @click="$router.push('/index')">确定</el-button>-->
<!--          <el-button @click="$router.push('/index')">返回</el-button>-->
<!--        </el-form-item>-->
<!--      </el-form>-->



    <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
      <el-form-item label="昵称" prop="pass">
        <el-input type="name" v-model="ruleForm.name" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="性别" prop="region">
        <el-select v-model="ruleForm.region" placeholder="请选择性别" style="width: 289px;">
          <el-option label="男" value="shanghai"></el-option>
          <el-option label="女" value="beijing"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="修改密码" prop="pass">
        <el-input type="password" v-model="ruleForm.pass" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="确认密码" prop="checkPass">
        <el-input type="password" v-model="ruleForm.checkPass" autocomplete="off"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
    </el-card>
  </div>
</template>

<script>

// import axios from 'axios';

export default {
  name: "",
  // data() {
  //   return {
  //     user: {},
  //     rules: {
  //       account: [
  //         {required: true, message: '请输入账号', trigger: 'blur'}
  //       ],
  //       password: [
  //         {required: true, message: '请输入密码', trigger: 'blur'},
  //         {min: 1, max: 32, message: '长度在 1 到 32 个字符', trigger: 'blur'}
  //       ],
  //     }
  //   }
  // },
  // methods: {
  //   login() {
  //     this.$refs.loginForm.validate((r) => {
  //       if (r) {
  //         axios.post('http://localhost:8090/api/user/login', this.user).then(res => {
  //           alert(res.data.msg);
  //           if (res.data.status === 1) {
  //             localStorage.setItem('TOKEN', res.data.data.token);
  //             this.$router.push('/index');
  //           }
  //           console.log(res);
  //         })
  //       } else {
  //         this.$message.warning('请填完信息后再登录');
  //       }
  //     })
  //   }
  // }




  data() {
    var checkAge = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('年龄不能为空'));
      }
      setTimeout(() => {
        if (!Number.isInteger(value)) {
          callback(new Error('请输入数字值'));
        } else {
          if (value < 18) {
            callback(new Error('必须年满18岁'));
          } else {
            callback();
          }
        }
      }, 1000);
    };
    var validatePass = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入密码'));
      } else {
        if (this.ruleForm.checkPass !== '') {
          this.$refs.ruleForm.validateField('checkPass');
        }
        callback();
      }
    };
    var validatePass2 = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请再次输入密码'));
      } else if (value !== this.ruleForm.pass) {
        callback(new Error('两次输入密码不一致!'));
      } else {
        callback();
      }
    };
    return {
      ruleForm: {
        pass: '',
        checkPass: '',
        age: ''
      },
      rules: {
        pass: [
          { validator: validatePass, trigger: 'blur' }
        ],
        checkPass: [
          { validator: validatePass2, trigger: 'blur' }
        ],
        age: [
          { validator: checkAge, trigger: 'blur' }
        ]
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('submit!');
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
}
</script>

<style lang="scss">
//防止代码流失，在style里面放lang="scss"，再给div一个id="login"，文件名为什么ID名就命名为什么，最后把样式都放进这个ID里面
#user {

  .el-card__body {
    padding: 55px;
  }

  .el-card__header {
    padding: 17px 20px;
    border-bottom: 1px solid #EBEEF5;
    box-sizing: border-box;
  }

  .el-input__inner {
    opacity: 0.8 !important;
  }
}

.label {
  font-size: 18px;
}
</style>